package com.yuqiao.read.design.iterator;

import java.util.Calendar;
import java.util.Iterator;

public class AlternatingDinerMenu  implements Iterator{
    MenuItem[] menuItems;
    int position;

    public AlternatingDinerMenu(MenuItem[] menuItems){
        this.menuItems = menuItems;
        Calendar instance = Calendar.getInstance();
        position = instance.get(Calendar.DAY_OF_WEEK) % 2;
    }

    @Override
    public boolean hasNext() {
        if(position>=menuItems.length || menuItems[position] == null){
            return false;
        }
        return true;
    }

    @Override
    public Object next() {
        MenuItem menuItem = menuItems[position];
        position = position + 2 ;
        return menuItem;
    }
}
